package logic

import (
	"context"
	"doctor-medicine-system/model/mysql"

	"doctor-medicine-system/dockerrpc/dockerrpc"
	"doctor-medicine-system/dockerrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedicineAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineAddLogic {
	return &MedicineAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 药品添加
func (l *MedicineAddLogic) MedicineAdd(in *dockerrpc.MedicineAddRequest) (*dockerrpc.MedicineAddResponse, error) {
	// todo: add your logic here and delete this line

	medicine := &mysql.Medicine{
		Name:     in.Name,
		Style:    in.Style,
		Address:  in.Address,
		Good:     in.Good,
		Num:      in.Num,
		Work:     in.Work,
		DockerId: int(in.DockerId),
	}

	err := medicine.MedicineAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &dockerrpc.MedicineAddResponse{
		MedicineId: int64(medicine.ID),
	}, nil
}
